#include <iostream>
#include<memory>

class Fruit
{
public:
    virtual void  name() = 0;
};
class Apple : public Fruit
{
public:
    void name() override
    {
        std::cout << "i am an apple" << std::endl;
    }
};
class Banana : public Fruit
{
    void name() override
    {
        std::cout << "i am an banana" << std::endl;
    }
};
class FruitFactory
{
public:
    static std::shared_ptr<Fruit> create(const std::string &name)
    {
        if (name == "apple")
        {
            return std::make_shared<Apple>();
        }
        else
        {
            return std::make_shared<Banana>();
        }
    }
};
int main()
{
    std::shared_ptr<Fruit> fruit = FruitFactory::create("apple");
    fruit->name();
    fruit  = FruitFactory::create("banana");
    fruit->name();

    return 0;
}